package pt.uma.gap.graph;

/**
 * Represent the node from the graph
 * 
 * @author Duarte Abreu
 *
 */
public class GraphNode {


	public enum NodeType { FOO, CONTEXT, REF, MEM }
	public enum NoteOrigin {FIELD, PARAM, LOCAL }
	public enum AccessPerm {unique, immutable, full, pure, share}

	private String name;
	private NodeType type;
	private NoteOrigin origin;
	private String valueType;
	private int position;

	private AccessPerm preAccessPerm;
	private AccessPerm postAccessPerm;


	public GraphNode(){

	}

	public GraphNode(String name, NodeType type,  String valueType) {
		this.name = name;
		this.type = type;
		this.valueType = valueType;

	}


	public NodeType getType() {
		return type;
	}

	public void setType(NodeType type) {
		this.type = type;
	}


	public String getValueType() {
		return valueType;
	}


	public void setValueType(String valueType) {
		this.valueType = valueType;
	}


	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}

	public void setOrigin(NoteOrigin origin) {
		this.origin = origin;
	}

	public NoteOrigin getOrigin() {
		return origin;
	}

	public int getPosition() {
		return position;
	}

	public void setPosition(int position) {
		this.position = position;
	}

	public void setPreAccessPerm(AccessPerm preAccessPerm) {
		this.preAccessPerm = preAccessPerm;
	}

	public AccessPerm getPreAccessPerm() {
		return preAccessPerm;
	}

	public void setPostAccessPerm(AccessPerm postAccessPerm) {
		this.postAccessPerm = postAccessPerm;
	}

	public AccessPerm getPostAccessPerm() {
		return postAccessPerm;
	}

	public String getLabel(){
		if((this.origin != null) && this.origin.equals(NoteOrigin.FIELD)){
			return "this."+getName().substring(1);
		}else{
			return getName();
		}
	}
	
	public String getLabelExtended(){

		return getLabel() + " ["+getLetter(preAccessPerm)+", "+getLetter(postAccessPerm)+"]";
	}

	private char getLetter(AccessPerm accessPerm) {
		switch (accessPerm) {
		case full:
			return  'F';
			
		case immutable:
			return  'I';
			
		case pure:
			return 'P';
			
		case share:
			return 'S';
			
		case unique:
			return 'U';
			
		default:
			
			return ' ';
		}

	}
}
